package com.csht.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csht.mapper.CshtShelvesMapper;
import com.csht.model.CshtShelves;
import com.csht.page.PagerModel;
import com.csht.service.CshtShelvesService;
import com.csht.vo.my.CshtShelvesVo;

/**
 * 已下架的商品
 * @author chenhuiyan
 *
 */
@Service
public class CshtShelvesServiceImpl implements CshtShelvesService {
	
	@Autowired
	private CshtShelvesMapper cshtShelvesMapper;

	@Override
	public Integer getShelvesNumberByUserId(Integer userId) throws Exception {
		Integer count = cshtShelvesMapper.getShelvesNumberByUserId(userId);
		return count;
	}

	/**
	 * 根据用户id查找已下架的商品
	 */
	@Override
	public PagerModel<CshtShelvesVo> getShelvesByUserId(Map<String, Integer> res) throws Exception {
		List<CshtShelvesVo> cshtShelvesVoList = cshtShelvesMapper.getShelvesByUserId(res);
		PagerModel<CshtShelvesVo> pagerModel = new PagerModel<CshtShelvesVo>();
		Integer totalSize = this.getShelvesNumberByUserId(res.get("userId"));
		Integer messagePageSize = res.get("messagePageSize");
		Integer offset = res.get("offset");
		pagerModel.setDates(cshtShelvesVoList);
		pagerModel.setMessagePageSize(messagePageSize);
		pagerModel.setOffset(offset);
		pagerModel.setTotalSize(totalSize);
		return pagerModel;
	}

	/**
	 * 插入下架商品记录
	 */
	@Override
	public void insertShelvesGoods(CshtShelves cshtShelves) throws Exception {
		cshtShelvesMapper.insertShelvesGoods(cshtShelves);
	}

	/**
	 * 根据id查找到原商品id
	 */
	@Override
	public Integer selectShelvesToGoodsIdById(Integer shelvesId) throws Exception {
		Integer goodsId = cshtShelvesMapper.selectShelvesToGoodsIdById(shelvesId);
		return goodsId;
	}

	/**
	 * 根据id删除记录
	 */
	@Override
	public void deleteShelvesGoodsById(Integer shelvesId) throws Exception {
		cshtShelvesMapper.deleteShelvesGoodsById(shelvesId);
	}

}
